<?php
/* wwwschool project

Copyright (C) 2009  Phillip Aldridge
Email : info@imi21.com
Web site http://www.imi21.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


/**
 *  File : listCoursesStudent.php
 *  called only via ajax 
 *  List all the lessons for the course which this student is allowed to do
 *  @ 
 */  
 

checkSession();

require '../../includes/classes/WS3tableview.php';
require '../../includes/classes/WS3user.php';
require '../../includes/classes/WS3course.php';
require '../../includes/classes/WS3lesson.php';

$user = new WS3_User(); 
if ($user->setUserID( $session->userID() ) )
{
  //$id  = ; // lesson id
  
  $lesson =new WS3_Lesson();
  $lesson->setLessonID( $_POST['id'] );
  
  $course=new WS3_Course();
  $course->setCourseID( $lesson->CourseID() );


  $table=new WS3_TableView('main',400);
  $table->setTitle( 'Listing modules in '.$course->CourseName().' : '.$lesson->LessonName().' for  '.$user->FullName() );

  $table->addColumnTH('Position');
  $table->addColumnTH('Name');
  $table->addColumn('Content','listStudentContents&amp;lid='.$lesson->LessonID() ); // need to take this with us
  $table->setAlternativeRows(true);
  $table->setInfoRow(true);
  
  
  $db=new WS3_Database();

  
// to do select only courses for which the student is not already enrolled  

 $q="SELECT m2l.id AS m2lid, m2l.position AS m2lposition,
  m2l.module_id AS m2lmodule_id,
  m.name AS mname, m.id AS mid
  FROM 
  module2lesson AS m2l
  RIGHT JOIN module AS m ON m.id=m2l.module_id
  WHERE m2l.lesson_id = '".$lesson->LessonID()."'
  AND m.active = '1'
  ORDER BY m2l.position
  "; // 

  
  if ($db->query($q))
  {
    $count = $db->numberRows();
    while ( $db->nextRecord() )
    {
       $table->addRow($db->f('mid'), array(
          'Position'=>$db->f('m2lposition'),
         'Name' => javaSafeString( $db->f('mname') )
        ));
  
    } 
    $table->addToInfoRow("<p>Count = $count </p>");
     echo $table->display();
    $message="Listing";
   
  }else{
    $message="Error : Empty list";
  }


}
/** Get menu */
require '../../includes/menus/topGoContent.php';
$menu=javaSafeString($menu);
echo "document.getElementById('topmenu').innerHTML='$menu';";

echo "document.getElementById('messages').innerHTML='$message';";
if (W3DEBUG)  $debug=new WS3_Debug();

?>
